Questions
42 of 45
1What is a pseudo-element in CSS?
2How are pseudo-elements different from pseudo-classes?
3What is the syntax of a pseudo-element?
4Name some commonly used pseudo-elements.
5What does the ::before pseudo-element do? What does the ::after pseudo-element do?
6How can you insert content using pseudo-elements?
7What is the difference between :before and ::before? Why were pseudo-elements changed from one colon (:) to two (::) in CSS3?
8What does the ::first-letter pseudo-element do?
9What does the ::first-line pseudo-element do?
10How can you style the first line of a paragraph differently?
11Can pseudo-elements be styled with animations or transitions?
12What’s the difference between using ::before and ::after?
13Can pseudo-elements be positioned using CSS positioning properties? Can pseudo-elements have background images or colors? How can you use pseudo-elements to create shapes or icons?
14Can you use multiple pseudo-elements on the same element?
15What is the ::selection pseudo-element used for?
16How does stacking and z-index affect pseudo-elements?
17Can pseudo-elements have child elements or content inside them?
18Can you apply pseudo-elements to replaced elements (like <img>)?
19How do pseudo-elements interact with display and overflow properties?
20What’s the difference between using pseudo-elements and real elements for decoration?
21How does inheritance work with pseudo-elements?
22Can pseudo-elements trigger JavaScript events (like click)?
23How can you control the generated content with pseudo-elements using attr()?
24Can pseudo-elements be used inside flex or grid layouts?
25How do you control the stacking order of ::before and ::after pseudo-elements?
26How can you create a tooltip using pseudo-elements?
27How can you make a custom underline or highlight effect using ::after?
28How can you make a quotation mark appear before a paragraph using pseudo-elements?
29How do you create a triangle or arrow shape using only CSS pseudo-elements?
30How can you use pseudo-elements to add icons without extra markup?
31How can you create a button hover animation using ::before or ::after?
32How can pseudo-elements help in implementing skeleton loaders or shimmer effects?
33How can you use ::before and ::after to clear floats?
34How can you create a border animation using pseudo-elements?
35How can pseudo-elements be used in responsive design?
36What is the ::marker pseudo-element and when is it used?
37What does the ::placeholder pseudo-element do?
38How does ::cue work with media elements?
39What is ::backdrop, and where is it used?
40What is the difference between ::file-selector-button and other input pseudo-elements?
41How does the ::part() pseudo-element work in Web Components?
42How is ::slotted() different from ::part() in shadow DOM styling?
43Can you style text highlights with pseudo-elements?
44How can ::selection be customized for accessibility and branding?
45What are the limitations of pseudo-elements compared to actual DOM elements?
42 / 45

How is ::slotted() different from ::part() in shadow DOM styling?

Understanding the ::slotted() Pseudo-Element in CSS

The ::slotted() pseudo-element is used in Web Components to style elements that are passed into a shadow DOM via <slot>. Unlike ::part(), which styles internal elements exposed via the part attribute, ::slotted() targets content projected from outside the shadow DOM.

Key Points
  1. 1

    ::slotted(selector) targets elements that are passed into a shadow DOM slot.

  2. 2

    It does not affect internal elements created inside the shadow DOM—only slotted (external) content.

  3. 3

    You can style properties like color, font, margin, and padding for the slotted elements.

  4. 4

    Only the top-level elements of the slot can be targeted; nested elements inside the slotted content cannot be selected with ::slotted().

Example: Styling Slotted Content

In this example, the ::slotted(.highlight) selector styles only the <p> element with class highlight that is passed into the <slot> of the shadow DOM. Other elements inside the shadow DOM remain unaffected.

Comparison with ::part()
  1. 1

    ::part() styles internal shadow DOM elements exposed via the part attribute.

  2. 2

    ::slotted() styles external elements projected into a shadow DOM slot.

  3. 3

    ::part() allows more granular control over internal structure; ::slotted() is limited to top-level slotted content.

  4. 4

    Use ::part() for theming internal parts and ::slotted() for styling content passed from outside the component.

Difficulty: 6/10
Topics: Shadow DOM styling, CSS pseudo-elements, Component encapsulation

Scenario Questions

0-2 years experience
  1. 1

    You're building a button component with a shadow DOM and want to let users style the text inside it — should you use ::slotted() or ::part()? Why?

  2. 2

    If a user passes a <span> inside a <slot> in your component, and you try to style it with ::part(), what happens and why?

  3. 3

    You set up a custom element with a slot and try to style its content using ::slotted(*) — but nothing changes. What’s the most likely mistake?

2-5 years experience
  1. 1

    A designer reports that the text inside your card component’s slot is inheriting global font styles even though you set a reset in the shadow DOM — how do you diagnose and fix this?

  2. 2

    Your team’s modal component uses ::part() to expose a close button, but QA says the button’s hover styles aren’t working in some browsers — what could be going wrong?

  3. 3

    You’re integrating a third-party web component that uses ::slotted() for content styling, but your app’s global CSS is overriding it unexpectedly — how do you isolate and resolve this?

5-8 years experience
  1. 1

    You’re designing a reusable form field component that needs to allow external styling of both the input (via slot) and the error icon (via part). How do you structure the shadow DOM and CSS to avoid style leakage while keeping flexibility?

  2. 2

    Your component library uses ::part() extensively for theming, but performance tests show slow repaints when users dynamically change themes. What’s the root cause and how would you optimize it?

  3. 3

    A legacy component uses ::slotted() to style user-provided content, but now you need to support nested components inside slots — what edge cases arise and how do you handle them without breaking existing consumers?

8+ years experience
  1. 1

    You’re leading a migration from a legacy CSS-in-JS component library to web components with shadow DOM. How do you decide which internal elements should be exposed via ::part() vs. which should remain hidden, and how do you communicate this to 10+ frontend teams?

  2. 2

    Your company’s design system uses ::part() for theming across 50+ components, but now you’re adding a new framework that doesn’t support shadow DOM. How do you architect a backward-compatible styling layer without sacrificing encapsulation?

  3. 3

    A critical component uses ::slotted() to style user-provided content, but it’s causing layout thrashing in high-frequency updates. How would you redesign the API and styling strategy to support dynamic, performant content insertion at scale?

Follow-up Questions

  • What happens if you try to style a slotted element with ::part()?
  • Can you use ::slotted() to style nested elements inside a slot?
  • How would you debug a case where a custom element’s internal part isn’t responding to external styles?